﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

//namespace FilteringData
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            var numbers = new int[] { -1, -32, 3, 5, -8, 13, 7, -41 };
//            var magnitude = from n in numbers where Math.Abs(n) > 5 select n;
//            foreach (var m in magnitude)
//                Console.WriteLine(m);
//            Console.ReadLine();
//        }
//    }
//}

//namespace OfTypeFilterDemo
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            var randomData = new object[] { 1, "two", 3, "four", 5.5, "six", 7M };

//            var canBeInt = from r in randomData.OfType<int>() select r;
//            foreach (var i in canBeInt)
//            {
//                Console.WriteLine(i);
//            }
//            Console.ReadLine();
//        }
//    }
//}

//namespace QuantifierDemo
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            var household = new List<FamilyMember>{
//                new FamilyMember{Name = "Paul Kimmel", Species = "Lunckhead in Chief", Gender = "Male" },
//                new FamilyMember{Name = "Dena Swanson", Species = "Boss", Gender = "Female" },
//                new FamilyMember{Name = "Alex Kimmel", Species = "Princess", Gender = "Female" },
//                new FamilyMember{Name = "Noah Kimmel", Species = "Annoying Brother", Gender = "Male" },
//                new FamilyMember{Name = "Joe Swanson", Species = "Homosapien", Gender = "Male" },
//                new FamilyMember{Name = "Ruby", Species = "Canine", Gender = "Female" },
//                new FamilyMember{Name = "Leda", Species = "Canine", Gender = "Female" },
//                new FamilyMember{Name = "Big Mama", Species = "Feline", Gender = "Female" }
//            };

//            bool anyCats = household.Any(m => m.Species == "Feline");
//            Console.WriteLine("Do you have any cats? {0}", anyCats);
//            bool allDogs = household.All(m => m.Species == "Canine");
//            Console.WriteLine("All gone to the dogs? {0}", allDogs);
//            Console.ReadLine();
//        }
//    }

//    public class FamilyMember
//    {
//        public string Name { get; set; }
//        public string Species { get; set; }
//        public string Gender { get; set; }
//    }
//}

//namespace SkipDemo
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            var ints = new int[] { 8, 2, 3, 4, 32, 5, 7, 8, 9, 10 };
//            var result1 = ints.TakeWhile(n => n%2 == 0);
//            var result2 = ints.Skip(3);
//            Array.ForEach(result1.ToArray(), n => Console.WriteLine(n));
//            Console.ReadLine();
//            Array.ForEach(result2.ToArray(), n => Console.WriteLine(n));
//            Console.ReadLine();
//        }
//    }
//}

//namespace RangeDemo2
//{
//    class Program
//    {
//        public class Customer
//        {
//            public int ID { get; set; }
//            public string CompanyName { get; set; }
//            public string City { get; set; }
//        }

//        static void Main(string[] args)
//        {
//            Action<Customer> print = c =>
//                Console.WriteLine("ID: {0}\nCustomer: {1}\nCity: {2}",
//                c.ID, c.CompanyName, c.City);

//            var customers = Enumerable.Repeat<Customer>(
//                new Customer
//                {
//                    ID = DateTime.Now.Millisecond,
//                    CompanyName = "Test Company",
//                    City = "Test City"
//                }, 100);

//            Array.ForEach(customers.ToArray(), c => print(c));
//            Console.ReadLine();
//        }
//    }
//}

//namespace SequenceEqualDemo
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            var folder1 = Directory.GetDirectories("C:\\");
//            var folder2 = Directory.GetDirectories("C:\\TEMP");

//            // are they equal
//            Console.WriteLine("Equal: " + folder1.SequenceEqual(folder2));
//            Console.ReadLine();

//            // What's the differnce?
//            var missingFolders = folder1.Except(folder2);

//            Console.WriteLine("Missing Folders: {0}", missingFolders.Count());
//            Array.ForEach(missingFolders.ToArray(),
//                folder => Console.WriteLine(folder));
//            Console.ReadLine();
//        }
//    }
//}

//namespace ElementDemo
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            var numbers = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

//            var first = (from n in numbers select n).First();
//            Console.WriteLine("First: {0}", first);
//            var firstOrDefault = (from n in numbers select n).FirstOrDefault(n => n > 10);
//            Console.WriteLine("First or default: {0}", firstOrDefault);

//            var last = (from n in numbers select n).Last();
//            Console.WriteLine("Last: {0}", last);
//            var lastOrDefault = (from n in numbers select n).LastOrDefault(n => n < 5);
//            Console.WriteLine("Last or default: {0}", lastOrDefault);

//            var single = (from n in numbers where n == 5 select n).Single();
//            Console.WriteLine("Single: {0}", single);
//            var singleOrDefault = (from n in numbers select n).SingleOrDefault(n => n == 3);
//            Console.WriteLine("Single or default: {0}", singleOrDefault);

//            var element = (from n in numbers where n < 8 select n).ElementAt(6);
//            Console.WriteLine("Element at 6: {0}", element);
//            var elementOrDefault = (from n in numbers select n).ElementAtOrDefault(11);
//            Console.WriteLine("Element at 11 or default: {0}", elementOrDefault);

//            Console.ReadLine();
//        }
//    }
//}

namespace ConcatenateDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            var numbers = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var moreNumbers = new int[] { 10, 11, 12, 13, 14, 15 };
            foreach (var n in numbers.Concat(moreNumbers))
                Console.WriteLine(n);
            Console.ReadLine();
        }
    }
}